package com.huatai.exchange.integration.vba.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.faneui.integration.http.HttpClientUtils;
import com.google.common.collect.Maps;
import com.huatai.exchange.integration.vba.AbstractVbaService;
import com.huatai.exchange.integration.vba.service.VbaFundNavDayService;
import com.huatai.vba.facade.bean.FundNavDayVo;
import com.huatai.vba.facade.bean.QueryFundNavDayVoListResp;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class VbaFundNavDayServiceImpl extends AbstractVbaService implements VbaFundNavDayService {

	@Override
	public FundNavDayVo queryFundNavDayVo(String dDate, String fundCode) throws BusinessException {
		FundNavDayVo vo = new FundNavDayVo();
		vo.setdDate(dDate);
		vo.setFundCode(fundCode);
		List<FundNavDayVo> list = queryFundNavDayVo(vo);
		if (ListUtils.isEmpty(list))
			return null;
		return list.get(0);
	}

	@Override
	public List<FundNavDayVo> queryFundNavDayVo(FundNavDayVo fundNavDayVo) throws BusinessException {
		String url = baseUrl + "fundnav/list";
		Map<String, Object> map = Maps.newHashMap();
		map.put("dDate", fundNavDayVo.getdDate());
		map.put("fundCode", fundNavDayVo.getFundCode());
		QueryFundNavDayVoListResp resp = HttpClientUtils.get(url, map, QueryFundNavDayVoListResp.class);
		return resp.getFundNavDayVos();
	}

}
